﻿#define _DEBUG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using EHR18;

namespace Common
{
    public abstract class Product
    {
       public  static string DATA_DIR =GenneralConfig.instance.OutputPath;
        public string ModelName { get; set; }
   
        public static object loker = new object();
       
        
        public Action<string> ShowMsg;
        public Action<List<TestSpan>> ShowTestSpan;

        public List<TestItem> TestItems { get; set; }

        #region 测试失败标志 B_Fail
        bool bFail = false;
        public bool B_Fail
        {
            get { return bFail; }
            set { bFail = value; }
        }
        #endregion

        #region 当前的测试项目 CurrentItem 
        public TestItem CurrentItem { get { return TestItems[Location]; } }
        #endregion

        #region GUID属性
        private string _GUID;
        public string GetGUID()
        {
            if (!string.IsNullOrEmpty(_GUID))
            {
                return _GUID;
            }
            _GUID = Guid.NewGuid().ToString();
            return _GUID;
        }
        #endregion

        #region 测试所在的位置 Location
        private int _location;
        public int Location
        {
            get
            {
                return _location;
            }
        }
        #endregion

        #region 测试产品 abstract Test()
        public abstract int Test();
        #endregion

#region 输出到目录
        public abstract void InsertTable();
#endregion


        #region 将 Location+1
        public void StepLocation()
        {
            _location++;
        }
        #endregion

        #region 当测试失败，把该产品之后的站位设置为不测试
        public void SetFail()
        {
            for (int i = _location + 1; i < TestItems.Count; i++)
            {
                TestItems[i].IsUse = false;
            }
            bFail = true;
        }
        #endregion


        #region 构造方法
        /// <summary>
        /// 参数构造，从Xml获取设置列表
        /// </summary>
        /// <param name="FileName"></param>
        public Product()
        {
          GenneralConfig g = GenneralConfig.instance;
          if( g.module!=null)
            {
                TestItems =CommonHelper.Clone(g.module.TestItems);
            }
        }
        #endregion


        #region 将字符串转换为数字
        public static decimal ChangeDataToD(string strData)
        {
            decimal dData;
            try
            {
                if (strData.ToUpper().Contains("E"))
                {
                    string[] splits = strData.Split(new char[] { 'E' });
                    dData = Convert.ToDecimal(Convert.ToDouble(splits[0]) * Math.Pow(10, Convert.ToDouble(splits[1])));
                }
                else
                {
                    dData = Convert.ToDecimal(strData);
                }
            }
            catch (Exception ex)
            {

                dData = 0;
            }
            return dData;
        } 
        #endregion
    }
}
